#include<iostream>
#include<cstdlib>
#include<unistd.h>

using namespace std;

int main()
{
    cerr<<"debug test :"<<getenv("METHOD")<<endl;
    std::string method = getenv("METHOD");
    cout<<"method:"<<method<<endl;
 
    std::string query_string;
    if(method == "GET")
    {
        query_string = getenv("QUERY_STRING");
        cerr<<"Debug QUERY_STRING:"<<query_string<<endl;
    }
    else if (method == "POST")
    {
        cerr<<"content-length:"<<getenv("CONTENT_LENGTH")<<endl;
        int content_length = atoi(getenv("CONTENT_LENGTH"));
        char c =0;
        while (content_length)
        {
            read(0,&c,1);
            query_string.push_back(c);
            content_length--;
        }  
        cerr<<"Debug POST CONTENT_LENGTH:"<<query_string<<endl;
    }
    else
    {

    }
    return 0;
}
